<template>
  <a-modal
    :title="title"
    :width="500"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    
    <a-form-model ref="form" :model="model" :rules="validatorRules">
      <a-form-model-item label="打卡模板" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signinTemplateId">
        <a-select v-model="model.signinTemplateId" placeholder="请选择打卡计划模板" >
          <a-select-option :value="item.dataId" v-for="item in signinTemplateList" :key="item.dataId">
            {{ item.signInName }}
          </a-select-option>
        </a-select>
      </a-form-model-item>
      
    </a-form-model>

  </a-modal>
</template>

<script>
  import { getAction, postAction, deleteAction } from '@/api/manage'
  import { mapGetters } from 'vuex'
  export default {
    name: 'ChangeTemplateModal',
    data() {
      return {
        title: '请选择打卡计划模板',
        visible: false,
        confirmLoading: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        validatorRules: {
          signinTemplateId: [{required: true, message: '请选择打卡计划模板!'}]
        },
        signinTemplateList: []
      }
    },
    created() {

    },
    methods: {
      ...mapGetters(["userInfo", "orgCode"]),
      add() {
        this.edit({})
      },
      edit(record) {
        this.visible = true
        this.model = Object.assign({}, record, {oldSigninTemplateId: record.signInTemplateId})
        this.getSigninTemplateList()
      },
      getSigninTemplateList() {
        postAction('/signin/template/list', { orgCode: this.orgCode() }).then(res => {
          if (res.success) {
            this.signinTemplateList = res.result
          }
        })
      },
      handleSubmit() {
        const that = this
        // 触发表单验证
        this.$refs.form.validate((valid) => {
          if (valid) {
            that.confirmLoading = true

            let model = {
              dataId: this.model.dataId,
              patientId: this.model.patientId,
              signinTemplateId: this.model.signinTemplateId,
              oldSigninTemplateId: this.model.oldSigninTemplateId,
              serviceStartTime: this.model.signInStartdate
            }
            console.log(model)
            postAction('/archive/reverse/scheme/update/signin', model).then((res) => {
              if (res.success) {
                that.$message.success("切换成功")
                that.$emit('ok')
                that.handleCancel();
              } else {
                that.$message.warning(res.message)
              }
            }).finally(() => {
              this.confirmLoading = false;
              
            })
          } else {
            return false
          }
        })
      },
      // 关闭
      handleCancel() {
        this.close()
      },
      close() {
        this.visible = false
        this.$refs.form.resetFields();
      }
    }
  }
</script>

<style scoped>
.avatar-uploader > .ant-upload {
  width: 104px;
  height: 104px;
}
.ant-upload-select-picture-card i {
  font-size: 49px;
  color: #999;
}

.ant-upload-select-picture-card .ant-upload-text {
  margin-top: 8px;
  color: #666;
}

.ant-table-tbody .ant-table-row td {
  padding-top: 10px;
  padding-bottom: 10px;
}

.drawer-bootom-button {
  position: absolute;
  bottom: -8px;
  width: 100%;
  border-top: 1px solid #e8e8e8;
  padding: 10px 16px;
  text-align: right;
  left: 0;
  background: #fff;
  border-radius: 0 0 2px 2px;
}
</style>